package com.service.impl;

import com.bean.*;
import com.dao.SellDao;
import com.dao.impl.SellDaoImpl;
import com.service.SellService;
import jdk.jshell.spi.ExecutionEnv;

import java.util.ArrayList;
import java.util.List;

public class SellServiceImpl implements SellService {

    private SellDao sellDao = new SellDaoImpl();
    @Override
    public Sell sellInit(User user, Customer customer,String address) {
        return sellDao.sellInit(user,customer,address);
    }

    @Override
    public List<SellInfo> getAllGoods(User user,Customer customer,String address) {
        Sell sell = new Sell();
        sell.setUser(user);
        sell.setCustomer(customer);
        sell.setAddress(address);
        return sellDao.getAllGoods(sell,address);
    }

    @Override
    public int addGoods(int key, int number, Sell sell) {
        return sellDao.addGoods(key,number,sell);
    }

    @Override
    public boolean deleteGoods(int key) {
        if (sellDao.deleteGoods(key) > 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean updateGoodsNumber(int key, int number) {
        if (sellDao.updateGoodsNumber(key,number) > 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean outWarehouse(User user, Customer customer,String address) {
        Sell sell = new Sell();
        sell = sellDao.sellInit(user,customer,address);
        List<SellInfo> sellInfos = new ArrayList<>();
        int money = sellDao.getMoney(user,customer,address);
        sellInfos = sellDao.getAllGoods(sell,address);
        if (sellDao.outWarehouse(sellInfos,money) > 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<Sell> getAllSell() {
        return sellDao.getAllSell();
    }

    @Override
    public Sell getSelectSell(int key) {
        return sellDao.getSelectSell(key);
    }

    @Override
    public List<SellInfo> getSellInfo(Sell sell) {
        return sellDao.getSellInfo(sell);
    }

    @Override
    public int getMoney(User user, Customer customer, String address) {
        return sellDao.getMoney(user,customer,address);
    }

    @Override
    public List<Sell> getFindSell(String custoerName, String startDate, String endDate) {
        return sellDao.getFindSell(custoerName,startDate,endDate);
    }
}
